home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Disk / PowerScan 2.0 / Prog. doc for pproc (Nisus) < prev    next >
Text File  |  1994-01-15  |  8KB  |  139 lines

  1. 
  2. PROGRAMMER’S INFO
  3.  
  4. How to Write
  5. PowerScan
  6. Preprocessor Addins
  7. 
  8.  
  9.  
  10.  
  11. Calling Specifications
  12. General notes
  13. Whenever PowerScan calls your preprocessor your resource file will be first in the resource path.
  14. It is possible that several scans run simultaneously so your preprocessor must be prepared to get called for different files in any order. Currently PowerScan calls the preprocessor repeatedly for one archive file to extract all contents before processing another file but that may change in the future. Use the file refCon fields (described below) to store reference numbers of the files that your preprocessor has opened.
  15. Resources
  16. Your preprocessor addin file must have type ’PScP’ and creator ’PScn’. In the resource fork you will need these resources:
  17. resource type
  18. resource ID
  19. contents
  20.  
  21. PScP
  22. 128
  23. code for your preprocessor; entrypoint must be at the beginning; PowerScan will load and lock this resource at launch time
  24.  
  25. PSpi
  26. 128
  27. info resource (use included ResEdit™ template)
  28.  
  29. icon suite
  30. (ICN#, icl4, icl8, ics#, ics4, ics8)
  31. 128
  32. icon suite for your preprocessor
  33.  
  34. STR#
  35. 128
  36. Short info text displayed in Preferences dialog box when user clicks “Info” button.
  37.  
  38.  
  39. The code resource must have its entrypoint at the beginning. It should be defined as:
  40.         procedure myPreProcessor (selector: longint; PPType: OSType;                                                             param1, param2: ptr; var globalRefCon: longint);
  41.  
  42. The selector field, param1 and param2 pointers and the refCon field are described below. The PPType field holds a four-character code that uniquely identifies your preprocessor. The unique code is used to prevent several copies of the same preprocessor to be installed simultaneously. Note that PowerScan currently only allows one preprocessor in each addin file but that this may change in the future.
  43. The info resource includes fields that tell PowerScan the name of your preprocessor, what file types it is interested in, and more. Use the ResEdit™ template that is included.
  44. Selectors
  45. These selectors are used when PowerScan communicates with your preprocessor addin:
  46. selector
  47. param1
  48. param2
  49. refCon
  50.  
  51. kPPAddinLoad
  52. unused (nil)
  53. unused (nil)
  54. free for use
  55.  
  56. kPPAddinPreprocessFile
  57. tFileInfoPtr
  58. tArchiveScanPtr
  59. free for use
  60.  
  61. kPPAddinCleanup
  62. unused (nil)
  63. unused (nil)
  64. free for use
  65.  
  66.  
  67. kPPAddinLoad
  68. Your preprocessor will get a kPPAddinLoad message when PowerScan opens it. This will happen once for every preprocessor whether it is disabled or not (in the Preferences dialog box). Disabling or enabling a preprocessor during runtime will not cause any messages to be sent.
  69. This is a good time to allocate memory that your preprocessor needs. Use the refCon field for holding your global data.
  70. kPPAddinPreprocessFile
  71. Whenever PowerScan finds a file that should be preprocessed by your addin it will send this message. The first parameter, param1, is a pointer to a tFileInfo data structure which contains data about the file. The second parameter, param2, points to a tArchiveScanRecord data structure which is used to return several files from the single input file.
  72. When returning a tFileInfo record you should set the dirID and vRefNum fields to the directory ID and volume reference number for the file you return. If this file is part of an archive you can set both fields to 0 to indicate that the file doesn’t exist on the disk.
  73. Set iconType to either iconApplication, iconDocument or iconFolder. PowerScan will convert these to corresponding archive icons if needed. The indentLevel counter should be increased when you go down one folder level and decreased when you leave a folder.
  74. The crDateStr and mdDateStr strings will be generated by PowerScan from the corresponding numeric fields. Just leave these strings untouched and everything will work fine. Leave the selected field untouched as well.
  75. The fileIndex field of the tArchiveScanRecord record will be set to 0 (zero) by PowerScan before the first call. The preprocessor should set this field to any other value (presumably 1) if it wants to return any more tFileInfo records. PowerScan will then call the preprocessor repeatedly until the fileIndex field is 0 or negative. The preprocessor can use this field as an index counter for the archive that it is processing (hence the name fileIndex).
  76. If the preprocessor returns a negative value in the fileIndex field, PowerScan will not add any file at all. For example, it is possible to write a filter that makes all alias files invisible to PowerScan in this way.
  77. The refCon field in the tArchiveScanRecord (which has nothing to do with the global refCon field) can be used for e.g. storing the reference number of the currently open archive file. As mentioned earlier PowerScan may in the future call your preprocessor with different files in any order so use this field to distinguish among the files your preprocessor is working on.
  78. kPPAddinCleanup
  79. When PowerScan quits it will send a kPPAddinCleanup message before it closes the preprocessor resource file. As with the kPPAddinLoad message this will happen even if the preprocessor is disabled.
  80. You should dispose of any memory that was allocated at startup.
  81. Some Type Definitions
  82. Note    See the included interface file for complete definitions.
  83. type
  84.     {--string types--}
  85.     tStr20 = string[20];
  86.     tStr31 = string[31];
  87.  
  88.     {--directory entry for a file or folder--}
  89.     tDelimiterType = (fileDelimiter, scanDelimiter);
  90.     tIconType = (iconApplication, iconArchiveApplication, iconDocument,
  91.                                 iconArchiveDocument, iconFolder, iconArchiveFolder, noIcon);
  92.     tTextStrType = tStr100;
  93.     tFileInfo = record
  94.             case fileInfoVariant : integer of
  95.                 {...more private variants here...}
  96.                 kFileInfoVariant: (
  97.                         fileName: tStr31;
  98.                         dirID: longint;
  99.                         vRefNum: integer;
  100.  
  101.                         iconType: tIconType;
  102.                         isAlias: boolean;
  103.                         fileFlags: integer;
  104.                         indentLevel: integer;
  105.                         fileSize: longint;
  106.                         crDate, mdDate: longint;
  107.                         fileType, fileCreator: OSType;
  108.                         fileVersion: numVersion;
  109.                         crDateStr, mdDateStr: tStr20;
  110.                         selected: boolean;
  111.                         indexInFolder: integer;
  112.                         internalFlag: boolean;
  113.                 )
  114.         end;
  115.     tFileInfoPtr = ^tFileInfo;
  116.  
  117.     {--record used when preprocessing an archive that contain multiple files--}
  118.     tArchiveScanRecord = record
  119.             fileIndex: integer;
  120.             refCon: longint;
  121.         end;
  122.     tArchiveScanPtr = ^tArchiveScanRecord;
  123. Examples
  124. Example 1
  125. Suppose your preprocessor is interested in alias files. When PowerScan finds an alias file it will call your preprocessor like this:
  126. •    selector = kPPAddinPreprocessFile param1 = tFileInfo for the alias file param2 = tArchiveScanRecord with fileIndex = 0 and refCon = 0
  127.     You can now resolve the alias and fill the tFileInfo record with information from the new file. You will not need to touch the indentLevel field as it is filled in for you. Set the fileIndex field to 0.
  128. Example 2
  129. Suppose your preprocessor reads Compact Pro archives and that PowerScan scans this file:
  130. MyArchive.cpt – FirstFile – SecondFile
  131. Then your filter would get called in this way:
  132. •    selector = kPPAddinPreprocessFile param1 = tFileInfo for MyArchive.cpt param2 = tArchiveScanRecord with fileIndex = 0 and refCon = 0
  133.     Your filter should open the file MyArchive.cpt and store the reference number in the refCon field. You won’t need to do any additional processing of the file at this point but you should set the fileIndex field to 1.
  134. •    selector = kPPAddinPreprocessFile param1 = tFileInfo for MyArchive.cpt param2 = tArchiveScanRecord with fileIndex = 1 and refCon = whatever you stored here
  135.     Fill in the tFileInfo record for the first file in the opened archive (don’t forget to increase the indentLevel counter one step) and set fileIndex to 2.
  136. •    selector = kPPAddinPreprocessFile param1 = tFileInfo for MyArchive.cpt param2 = tArchiveScanRecord with fileIndex = 2 and refCon = whatever you stored here
  137.      Fill in the tFileInfo record for the second file in the opened archive, close the archive and set fileIndex to 0 to indicate that there are no more files in the archive.
  138.  
  139.